<?php
namespace app\Admin\controller;
use app\Admin\model\News as NewsModel;
use app\admin\controller\Base;

class News extends Base
{
    public function index()
    {
        //初始化curl
        $curl = curl_init();
        // var_dump($curl);

        // 设置APIKEY   URL
        // $apikey = "b287e292e4006b7254acfc392b2ce43d";//聚合
        $apikey = "3610b512d19544019a9613abd9a311b5";//易源
        $apiid = "32421";//易源
        $word = urlencode('lol');//%E8%8B%B1%E9%9B%84%E8%81%94%E7%9B%9F
        // echo 'http://v.juhe.cn/toutiao/index?key='.$apikey.'&num=10&keyword='.$word;
        // die;

        // http://route.showapi.com/109-35
        //CURL配置
        curl_setopt($curl, CURLOPT_URL, 'http://route.showapi.com/109-35?showapi_appid='.$apiid.'&showapi_sign='.$apikey.'&title=lol&maxResult=10');

        // curl_setopt($curl, CURLOPT_URL, 'http://v.juhe.cn/toutiao/index?key='.$apikey.'&word='.$word);

        /*'http://api.tianapi.com/keji/?key='.$apikey.'&num=10&word='.$word*/ 
        //将curl_exec()获取的信息 以文件流的形式,而不是直接输出的形式得到
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        //curl执行
        $data = curl_exec($curl);

        //关闭curl
        curl_close($curl);

        //处理JSON数据

        $jsonObj = json_decode($data);
        //提取文章信息
        // $newslist = $jsonObj->newslist;
        // var_dump($jsonObj->showapi_res_body->pagebean->contentlist);
        // echo '<pre>';
        // print_r($jsonObj->showapi_res_body->pagebean->contentlist);
        // var_dump($data);
        // die();
        $this->assign('list', $jsonObj->showapi_res_body->pagebean->contentlist);
        return $this->fetch('news/index');
    }
}
